package org.cornland.systemWarning.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.cornland.systemWarning.model.DataExceptionAlarm;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Hawk Tang
 * @since 2021-11-03
*/

@Mapper
public interface DataExceptionAlarmMapper extends BaseMapper<DataExceptionAlarm> {

    @Select("SELECT * FROM data_exception_alarm " +
            "where type = #{type} " +
            "and well_id = #{wellId} " +
            "ORDER BY time desc " +
            "limit 1 ")
    DataExceptionAlarm getLast(@PathVariable("wellId") String wellId, @PathVariable("type") Integer type);

    @Select("SELECT * FROM data_exception_alarm " +
            "where type = #{type} " +
            "and well_id = #{wellId} " +
            "and tag = #{tag} " +
            "and pi_type = #{piType} " +
            "ORDER BY time desc " +
            "limit 1 ")
    DataExceptionAlarm getLastWithTag(@PathVariable("wellId") String wellId, @PathVariable("type") Integer type, @PathVariable("tag") String tag, @PathVariable("piType") Integer piType);

    @Select("selcet * from data_exception_alarm_config where type=#{type}")
    Map<String, Object> findDataExceptionAlarmConfig(@Param("type") int type);
}